package com.examlpe.rabbitmqdome.controller;

import com.examlpe.rabbitmqdome.constant.Contants;
import jakarta.websocket.server.PathParam;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/producer")
@RestController
public class ProducerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/work")
    public String work() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("",
                    Contants.WORK_QUEUE,"hello Spring amqp:work"+i);
        }
        return "发送成功";
    }
    @RequestMapping("/fanout")
    public String fanout() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend(
                    Contants.FANOUT_EXCHANGE,"","hello Spring amqp:fanout"+i);
        }
        return "发送成功";
    }
    @RequestMapping("/direct/{routingKey}")
    public String direct(@PathVariable("routingKey") String rountingKey) {
        rabbitTemplate.convertAndSend(Contants.DIRECT_EXCHANGE,rountingKey,
                "hello Spring amqp: direct My rountingKey is "+rountingKey);
        return "发送成功";
    }
    @RequestMapping("/topic/{routingKey}")
    public String topic(@PathVariable("routingKey") String rountKey) {
        rabbitTemplate.convertAndSend(Contants.TOPIC_ENCHANGE,rountKey,
                "hello Spring  amqp: topic My Routingfkey is" + rountKey);
        return "发送成功";
    }
}
